#include "../include/unicebot_gui/UnicebotNode.hpp"
#include <QDesktopWidget>
#include <QApplication>


QApplication* application ;

void center(QWidget &widget) {
	ROS_WARN("center");
	int x, y;
	int screenWidth;
	int screenHeight;

	int WIDTH = 280;
	int HEIGHT = 270;

	QDesktopWidget *desktop = QApplication::desktop();

	screenWidth = desktop->width();
	screenHeight = desktop->height();

	x = (screenWidth - WIDTH) / 2;
	y = (screenHeight - HEIGHT) / 2;

	widget.setGeometry(x, y, WIDTH, HEIGHT);
}

void createControls(QWidget* win){


}

int main(int argc, char *argv[]) {
	ROS_WARN("main");

	application = new QApplication(argc, argv);

	unicebot_gui::KinectWidget* win = new unicebot_gui::KinectWidget();
	unicebot_gui::UnicebotNode* node = new unicebot_gui::UnicebotNode(argc, argv, win);

	// Create windo and controls
	//
	//note j'utilise des refs pour m'amuser au lieu de pointeurs

	win->setWindowTitle("Unicebot GUI");
	QPushButton* button1 = new QPushButton("One");
	QPushButton* button2 = new QPushButton("Two");
	QPushButton* button3 = new QPushButton("Three");
	QPushButton* button4 = new QPushButton("Four");
	QPushButton* button5 = new QPushButton("Five");

	QHBoxLayout* layout = new QHBoxLayout;
	layout->addWidget(button1);
	layout->addWidget(button2);
	layout->addWidget(button3);
	layout->addWidget(button4);
	layout->addWidget(button5);

	win->setLayout(layout);

	win->show();
	center(*win);

	ROS_WARN("app.connect");
	application->connect(application, SIGNAL(lastWindowClosed()), application, SLOT(quit()));

	// Démarrer le QThread (classe mere)
	//
	ROS_WARN("Node start");
	node->init();
	node->start();

	// Demarrer le thread QT
	//
	ROS_WARN("exec");
	int result = application->exec();

	ROS_WARN("Fin thread main");
	node->stop=true;
	return result;
}
